/**
 * Created by sioxa on 2016/12/25 0025.
 */
// import * as def from '../config/def'
import { cookie } from 'vux'
export default {
  state: {
    showfoot: false,
    histroyshoplist:[],
    effect:"effect"
  },
  mutations: {
    setsilderture(state) {
      state.showfoot = true;
    },
    setsilderfalse(state) {
      state.showfoot = false;
    },
    setsilderfalse(state) {
      state.showfoot = false;
    },
    setshoplist(state,second){
      if(second) {
        state.histroyshoplist.push(second);
        document.cookie = 'foo='+state.histroyshoplist
      }
    },
    clearshoplist(state) {
      state.histroyshoplist=[];
      document.cookie = 'foo=';
    }
  },
 actions: {
    setshoplist({commit, state}, options){
      // if("".indexOf.call(state.histroyshoplist,options.text1.replace(/(^\s+)|(\s+$)/g, ""))  > -1){
      //   return;
      // }
      let list = state.histroyshoplist;
      let text1 = options.text1.replace(/(^\s+)|(\s+$)/g, "");
      if(list.length > 0){
          for( let i = 0; i < list.length; i++ ){
              if(text1 == list[i]){
                text1='';//找到相同的立马撤回
                break;
              } 
          }
      }
    commit('setshoplist', text1)
      
    },
    clearshoplist({commit, state}, options){
      commit('clearshoplist')
    },

    seteffect({commit, state},options){
        state.effect = options.effect
    }


  },
  getters: {
    getshowfoot: state =>
    state.showfoot,
    geteffect:state=>
    state.effect,
    getshoplist: function(state){
      let foo = cookie.get('foo');
      if(foo && state.histroyshoplist.length==0){
          state.histroyshoplist = foo.split(",");
      } 
      return state.histroyshoplist
    }
  }
}
